package model;

import protocol.JTT1078_2016.JTT1078_2016Cmd;
import utils.ExceptionUtils;
import utils.HexUtils;
import protocol.JTT1078_2016.JTT1078_2016Utils;
import utils.StringUtils;

import java.util.HashMap;
import java.util.List;

/**
 * 音视频通讯协议 JTT1078-2016协议
 */
public class Protocol1078_2016Model extends IModel {

    private final static int Protocol_Analysis = 0;//数据内容解析
    private final static int Protocol_Check = 1;//数据校验

    @Override
    protected void initTypes(List<String> list) {
        list.add(Protocol_Analysis,"数据内容解析");
        list.add(Protocol_Check,"数据校验");
    }

    private JTT1078_2016Cmd mTempCmd = null;

    @Override
    public String change(String input) {
        try{

            input = StringUtils.formatProtocol(input);

            byte[] data = JTT1078_2016Utils.data1078UnEscape(HexUtils.toHexBytes(input.trim()));

            JTT1078_2016Cmd JTT10782016Cmd = new JTT1078_2016Cmd(data);

            byte order1078 = JTT10782016Cmd.order();
            byte subOrder1078 = JTT10782016Cmd.suOrder();

            if(order1078 == 0x00&&subOrder1078 == 0x01){
                return handle0001(JTT10782016Cmd);
            }else if(order1078 == 0x00&&subOrder1078 == 0x02){
                return handle0002(JTT10782016Cmd);
            }else if (order1078 == 0x01&&subOrder1078 == 0x04){
                return handle0104(JTT10782016Cmd);
            }else if (order1078 == 0x12&&subOrder1078 == 0x05){
                return handle1205(JTT10782016Cmd);
            }else if (order1078 == 0x12&&subOrder1078 == 0x06){
                return handle1206(JTT10782016Cmd);
            }else if (order1078 == (byte) 0x81&&subOrder1078 == 0x03){
                return handle8103(JTT10782016Cmd);
            }else if (order1078 == (byte) 0x81&&subOrder1078 == 0x06){
                return handle8106(JTT10782016Cmd);
            }else if (order1078 == (byte) 0x91&&subOrder1078 ==0x01){
                return handle9101(JTT10782016Cmd);
            }else if (order1078 == (byte) 0x91&&subOrder1078 ==0x02){
                return handle9102(JTT10782016Cmd);
            }else if (order1078 == (byte) 0x92&&subOrder1078 ==0x05){
                return handle9205(JTT10782016Cmd);
            }else if (order1078 == (byte) 0x92&&subOrder1078 ==0x06){
                return handle9206(JTT10782016Cmd);
            }else if (order1078 == (byte) 0x92&&subOrder1078 ==0x01){
                return handle9201(JTT10782016Cmd);
            }else if (order1078 == (byte) 0x92&&subOrder1078 ==0x02){
                return handle9202(JTT10782016Cmd);
            }else if (order1078 == (byte) 0x92&&subOrder1078 ==0x07){
                return handle9207(JTT10782016Cmd);
            }

            return "找不到该命令！";
        }catch (Exception e){
            return "数据校验失败\n"+ ExceptionUtils.getExceptionMsg(e);
        }
    }

    private String handle0001(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("Hisi->LCD:通用应答0x0001");
        builder.append("\r\n");

        builder.append("应答流水号："+cmd.readWORD());
        builder.append("\r\n");

        builder.append("应答ID："+cmd.readBCD(2));
        builder.append("\r\n");

        HashMap<Integer,String> type1List = new HashMap<>();
        type1List.put(0,"成功/确认");
        type1List.put(1,"失败");
        type1List.put(2,"消息有误");
        type1List.put(3,"不支持");

        int type = cmd.readInt(1);
        builder.append("结果("+type+")："+type1List.getOrDefault(type,"未定义"));

        return builder.toString();
    }

    private String handle0002(JTT1078_2016Cmd JTT10782016Cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:心跳");
        builder.append("\r\n");

        return builder.toString();
    }


    private String handle0104(JTT1078_2016Cmd cmd) {

        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:参数查询应答0x0104（自定义命令）");
        builder.append("\r\n");

        builder.append("应答流水号："+cmd.readWORD());
        builder.append("\r\n");

        int size = cmd.readInt(1);
        builder.append("参数数量："+size);
        builder.append("\r\n");
        builder.append("参数ID列表：");
        builder.append("\r\n");

        for (int i=0;i<size;i++){

            String id = cmd.readBCD(4);
            builder.append("    参数ID："+id);
            builder.append("\r\n");
            int valueLen = cmd.readInt(1);
            builder.append("    参数长度："+valueLen);
            builder.append("\r\n");

            if (id.equals("00 00 00 77 ")){
                builder.append(handle0104_77(cmd.copy()));
                cmd.moveIndex(valueLen);
            }else{
                builder.append("参数内容："+cmd.readBCD(valueLen));
            }

            builder.append("\r\n");

        }

        return builder.toString();
    }

    private String handle0104_77(JTT1078_2016Cmd cmd) {

        StringBuilder builder = new StringBuilder();
        builder.append("    摄像头参数查询应答/摄像头参数设置 0x77");
        builder.append("\r\n");

        HashMap<Integer,String> type1List = new HashMap<>();
        type1List.put(0,"CBR（固定码率）");
        type1List.put(1,"VBR（可变码率）");
        type1List.put(2,"ABR（平均码率）");

        HashMap<Integer,String> type2List = new HashMap<>();
        type2List.put(0,"QCIF");
        type2List.put(1,"CIF");
        type2List.put(2,"WCIF");
        type2List.put(3,"D1");
        type2List.put(4,"WD1");
        type2List.put(5,"720P");
        type2List.put(6,"1080P");

        int size = cmd.readInt(1);
        for (int i=0;i<size;i++){
            builder.append("    通道号："+cmd.readInt(1));
            builder.append("\r\n");

            int type = cmd.readInt(1);
            builder.append("        实时流编码模式("+type+")："+type1List.getOrDefault(type,"未定义"));
            builder.append("\r\n");
            int type2 = cmd.readInt(1);
            builder.append("        实时流分辨率("+type2+")："+type2List.getOrDefault(type2,"未定义"));
            builder.append("\r\n");
            builder.append("        实时流关键帧间隔："+cmd.readWORD());
            builder.append("\r\n");
            builder.append("        实时流目标帧率："+cmd.readInt(1));
            builder.append("\r\n");
            builder.append("        实时流目标码率："+cmd.readDWORD());
            builder.append("\r\n");

            int type3 = cmd.readInt(1);
            builder.append("        存储流编码模式("+type3+")："+type1List.getOrDefault(type3,"未定义"));
            builder.append("\r\n");
            int type4 = cmd.readInt(1);
            builder.append("        存储流分辨率("+type4+")："+type2List.getOrDefault(type4,"未定义"));
            builder.append("\r\n");
            builder.append("        存储流关键帧间隔："+cmd.readWORD());
            builder.append("\r\n");
            builder.append("        存储流目标帧率："+cmd.readInt(1));
            builder.append("\r\n");
            builder.append("        存储流目标码率："+cmd.readDWORD());
            builder.append("\r\n");

            int osd = cmd.readWORD();
            builder.append("        水印叠加设置(0为不叠加，1为叠加）：");
            builder.append("\r\n");
            builder.append("            日期和时间："+(osd&0x01));
            builder.append("\r\n");
            builder.append("            车牌号码："+(osd>>1&0x01));
            builder.append("\r\n");
            builder.append("            逻辑通道号："+(osd>>2&0x01));
            builder.append("\r\n");
            builder.append("            经纬度："+(osd>>3&0x01));
            builder.append("\r\n");
            builder.append("            行驶记录速度："+(osd>>4&0x01));
            builder.append("\r\n");
            builder.append("            卫星定位速度："+(osd>>5&0x01));
            builder.append("\r\n");
            builder.append("            连续驾驶时间："+(osd>>6&0x01));
            builder.append("\r\n");
            builder.append("\r\n");
        }

        return builder.toString();
    }

    private String handle1205(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("Hisi->LCD:终端上传音视频资源列表0x1205（历史视频检索应答）");
        builder.append("\r\n");

        if (cmd.isSubPack){
            if (cmd.sumPackNum > 1&&cmd.currentPack == 1){
                this.mTempCmd = cmd;
            }else{
                this.mTempCmd.addSubPack(cmd);
            }

            if (cmd.sumPackNum != cmd.currentPack){
                builder.append("数据不完整，请传入分包。");
                return builder.toString();
            }

            cmd = mTempCmd;
        }

        builder.append("对应查询命令的流水号："+cmd.readWORD());
        builder.append("\r\n");

        int sum = cmd.readDWORD();
        builder.append("音视频资源总数："+sum);
        builder.append("\r\n");

        builder.append("音视频资源列表：");
        builder.append("\r\n");

        //分包有可能导致异常
        try{
            for (int i = 0;i<sum;i++){
                builder.append("    逻辑通道号："+cmd.readInt(1));
                builder.append("\r\n");
                builder.append("    开始时间："+cmd.readBCD(6));
                builder.append("\r\n");
                builder.append("    结束时间："+cmd.readBCD(6));
                builder.append("\r\n");
                builder.append("    报警标识1："+cmd.readBCD(4));
                builder.append("\r\n");
                builder.append("    报警标识2："+cmd.readBCD(4));
                builder.append("\r\n");

                int type = cmd.readInt(1);
                HashMap<Integer,String> typeList = new HashMap<>();
                typeList.put(0,"音视频");
                typeList.put(1,"音频");
                typeList.put(2,"视频");
                typeList.put(3,"视频或音频");

                builder.append("    音视频资源类型("+type+")："+typeList.getOrDefault(type,"未定义"));
                builder.append("\r\n");

                int stream = cmd.readInt(1);
                HashMap<Integer,String> streamList = new HashMap<>();
                streamList.put(0,"所有码流");
                streamList.put(1,"主码流");
                streamList.put(2,"子码流");

                builder.append("    码流类型("+stream+")："+streamList.getOrDefault(stream,"未定义"));
                builder.append("\r\n");

                int storage = cmd.readInt(1);
                HashMap<Integer,String> storageList = new HashMap<>();
                storageList.put(0,"所有存储器");
                storageList.put(1,"主存储器");
                storageList.put(2,"子存储器");
                builder.append("    存储器类型("+storage+")："+storageList.getOrDefault(storage,"未定义"));
                builder.append("\r\n");

                builder.append("    文件大小："+cmd.readDWORD());
                builder.append("\r\n");
                builder.append("\r\n");
            }
        }catch (Exception e){
            builder.append(ExceptionUtils.getExceptionMsg(e));
        }


        return builder.toString();
    }

    private String handle1206(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("Hisi->LCD:文件上传完成通知0x1206（历史视频导出完成通知）");
        builder.append("\r\n");
        builder.append("应答流水号："+cmd.readWORD());
        builder.append("\r\n");

        int res = cmd.readInt(1);
        HashMap<Integer,String> resList = new HashMap<>();
        resList.put(0,"成功");
        resList.put(1,"失败");
        builder.append("结果("+res+")："+resList.getOrDefault(res,"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle8103(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:参数设置0x8103");
        builder.append("\r\n");

        int size = cmd.readInt(1);
        builder.append("参数数量："+size);
        builder.append("\r\n");
        builder.append("参数ID列表：");
        builder.append("\r\n");

        for (int i=0;i<size;i++){

            String id = cmd.readBCD(4);
            builder.append("    参数ID："+id);
            builder.append("\r\n");
            int valueLen = cmd.readInt(1);
            builder.append("    参数长度："+valueLen);
            builder.append("\r\n");

            if (id.equals("00 00 00 77 ")){
                builder.append(handle0104_77(cmd.copy()));
                cmd.moveIndex(valueLen);
            }else{
                builder.append("参数内容："+cmd.readBCD(valueLen));
            }

            builder.append("\r\n");

        }

        return builder.toString();
    }

    private String handle8106(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:查询Hisi参数");
        builder.append("\r\n");
        int size = cmd.readInt(1);

        builder.append("参数数量："+size);
        builder.append("\r\n");

        for (int i =0;i<size;i++){
            String id = cmd.readBCD(4);

            if (id.equals("00 00 00 77 ")){
                builder.append("ID："+id+"(查询Hisi摄像头参数)");
            }else{
                builder.append("ID："+id);
            }
            builder.append("\r\n");
        }

        return builder.toString();
    }

    private String handle9101(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:实时视频传输请求0x9101（播放实时视频）");
        builder.append("\r\n");

        int size = cmd.readInt(1);
        builder.append("服务器IP地址长度："+size);
        builder.append("\r\n");
        builder.append("服务器IP地址："+cmd.readString(size));
        builder.append("\r\n");
        builder.append("TCP端口号："+cmd.readWORD());
        builder.append("\r\n");
        builder.append("UDP端口号："+cmd.readWORD());
        builder.append("\r\n");

        builder.append("逻辑通道号："+cmd.readInt(1));
        builder.append("\r\n");

        int type = cmd.readInt(1);
        HashMap<Integer,String> typeList = new HashMap<>();
        typeList.put(0,"音视频");
        typeList.put(1,"视频");
        typeList.put(2,"双向对讲");
        typeList.put(3,"监听");
        typeList.put(4,"中心广播");
        typeList.put(5,"透传");
        builder.append("资源类型("+type+")："+typeList.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        int stream = cmd.readInt(1);
        HashMap<Integer,String> streamList = new HashMap<>();
        streamList.put(0,"主码流");
        streamList.put(1,"子码流");

        builder.append("码流类型("+stream+")："+streamList.getOrDefault(stream,"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle9102(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:音视频实时传输控制0x9102（关闭实时视频）");
        builder.append("\r\n");

        builder.append("逻辑通道号："+cmd.readInt(1));
        builder.append("\r\n");

        int order = cmd.readInt(1);
        HashMap<Integer,String> orderList = new HashMap<>();
        orderList.put(0,"关闭音视频传输命令");
        orderList.put(1,"切换码流（增加暂停和继续）");
        orderList.put(2,"暂停该通道所有流的发送");
        orderList.put(3,"恢复暂停前流的发送，与暂停前的流类型一致");
        orderList.put(4,"关闭双向对讲");
        builder.append("控制指令("+order+")："+orderList.getOrDefault(order,"未定义"));
        builder.append("\r\n");

        int type = cmd.readInt(1);
        HashMap<Integer,String> typeList = new HashMap<>();
        typeList.put(0,"关闭该通道有关的音视频数据");
        typeList.put(1,"只关闭该通道有关的音频，保留该通道有关的视频");
        typeList.put(2,"只关闭该通道有关的视频，保留该通道有关的音频");
        builder.append("关闭音视频类型("+type+")："+typeList.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        int stream = cmd.readInt(1);
        HashMap<Integer,String> streamList = new HashMap<>();
        streamList.put(0,"主码流");
        streamList.put(1,"子码流");
        builder.append("切换码流类型("+stream+")："+streamList.getOrDefault(stream,"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle9201(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:录像回放请求0x9201（播放历史视频）");
        builder.append("\r\n");

        int size = cmd.readInt(1);
        builder.append("服务器IP地址长度："+size);
        builder.append("\r\n");
        builder.append("服务器IP地址："+cmd.readString(size));
        builder.append("\r\n");
        builder.append("TCP端口号："+cmd.readWORD());
        builder.append("\r\n");
        builder.append("UDP端口号："+cmd.readWORD());
        builder.append("\r\n");

        builder.append("逻辑通道号："+cmd.readInt(1));
        builder.append("\r\n");

        int type = cmd.readInt(1);
        HashMap<Integer,String> typeList = new HashMap<>();
        typeList.put(0,"音视频");
        typeList.put(1,"音频");
        typeList.put(2,"视频");
        typeList.put(3,"视频或音频");

        builder.append("音视频类型("+type+")："+typeList.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        int stream = cmd.readInt(1);
        HashMap<Integer,String> streamList = new HashMap<>();
        streamList.put(0,"所有码流");
        streamList.put(1,"主码流");
        streamList.put(2,"子码流");

        builder.append("码流类型("+stream+")："+streamList.getOrDefault(stream,"未定义"));
        builder.append("\r\n");

        int storage = cmd.readInt(1);
        HashMap<Integer,String> storageList = new HashMap<>();
        storageList.put(0,"主存储器或灾备存储器");
        storageList.put(1,"主存储器");
        storageList.put(2,"灾备存储器");
        builder.append("存储器类型("+storage+")："+storageList.getOrDefault(storage,"未定义"));
        builder.append("\r\n");

        int way = cmd.readInt(1);
        HashMap<Integer,String> wayList = new HashMap<>();
        wayList.put(0,"正常回放");
        wayList.put(1,"快进回放");
        wayList.put(2,"关键帧快退回放");
        wayList.put(3,"关键帧播放");
        wayList.put(4,"单帧上传");

        builder.append("回放方式("+way+")："+wayList.getOrDefault(way,"未定义"));
        builder.append("\r\n");

        int multiple = cmd.readInt(1);
        HashMap<Integer,String> multipleList = new HashMap<>();
        multipleList.put(0,"无效");
        multipleList.put(1,"1倍");
        multipleList.put(2,"2倍");
        multipleList.put(3,"4倍");
        multipleList.put(4,"8倍");
        multipleList.put(5,"16倍");
        builder.append("快进或快退倍数-仅回放方式为1或2时有效("+multiple+")："+multipleList.getOrDefault(multiple,"未定义"));
        builder.append("\r\n");

        builder.append("开始时间："+cmd.readBCD(6));
        builder.append("\r\n");
        builder.append("结束时间："+cmd.readBCD(6));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle9202(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:历史视频回放控制0x9202");
        builder.append("\r\n");
        builder.append("逻辑通道号："+cmd.readInt(1));
        builder.append("\r\n");

        int way = cmd.readInt(1);
        HashMap<Integer,String> wayList = new HashMap<>();
        wayList.put(0,"正常回放");
        wayList.put(1,"暂停回放");
        wayList.put(2,"结束回放");
        wayList.put(3,"快进回放");
        wayList.put(4,"关键帧快退回放");
        wayList.put(5,"拖动回放");
        wayList.put(6,"关键帧播放");

        builder.append("回放控制("+way+")："+wayList.getOrDefault(way,"未定义"));
        builder.append("\r\n");

        int multiple = cmd.readInt(1);
        HashMap<Integer,String> multipleList = new HashMap<>();
        multipleList.put(0,"无效");
        multipleList.put(1,"1倍");
        multipleList.put(2,"2倍");
        multipleList.put(3,"4倍");
        multipleList.put(4,"8倍");
        multipleList.put(5,"16倍");
        builder.append("快进或快退倍数-仅回放方式为3或4时有效("+multiple+")："+multipleList.getOrDefault(multiple,"未定义"));
        builder.append("\r\n");

        builder.append("拖动回放位置(回放控制为5时有效)："+cmd.readBCD(6));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle9205(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:查询资源列表0x9025（历史视频检索）");
        builder.append("\r\n");
        builder.append("逻辑通道号："+cmd.readInt(1));
        builder.append("\r\n");
        builder.append("开始时间："+cmd.readBCD(6));
        builder.append("\r\n");
        builder.append("结束时间："+cmd.readBCD(6));
        builder.append("\r\n");
        builder.append("报警标识1："+cmd.readBCD(4));
        builder.append("\r\n");
        builder.append("报警标识2："+cmd.readBCD(4));
        builder.append("\r\n");

        int type = cmd.readInt(1);
        HashMap<Integer,String> typeList = new HashMap<>();
        typeList.put(0,"音视频");
        typeList.put(1,"音频");
        typeList.put(2,"视频");
        typeList.put(3,"视频或音频");

        builder.append("音视频资源类型("+type+")："+typeList.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        int stream = cmd.readInt(1);
        HashMap<Integer,String> streamList = new HashMap<>();
        streamList.put(0,"所有码流");
        streamList.put(1,"主码流");
        streamList.put(2,"子码流");

        builder.append("码流类型("+stream+")："+streamList.getOrDefault(stream,"未定义"));
        builder.append("\r\n");

        int storage = cmd.readInt(1);
        HashMap<Integer,String> storageList = new HashMap<>();
        storageList.put(0,"所有存储器");
        storageList.put(1,"主存储器");
        storageList.put(2,"子存储器");
        builder.append("存储器类型("+storage+")："+storageList.getOrDefault(storage,"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle9206(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:文件上传指令0x9206（历史视频导出）");
        builder.append("\r\n");

        int size = cmd.readInt(1);
        builder.append("服务器IP地址长度："+size);
        builder.append("\r\n");
        builder.append("服务器IP地址："+cmd.readString(size));
        builder.append("\r\n");
        builder.append("端口："+cmd.readWORD());
        builder.append("\r\n");
        builder.append("用户名："+cmd.readString(cmd.readInt(1)));
        builder.append("\r\n");
        builder.append("密码："+cmd.readString(cmd.readInt(1)));
        builder.append("\r\n");
        builder.append("文件上传路径："+cmd.readString(cmd.readInt(1)));
        builder.append("\r\n");

        builder.append("逻辑通道号："+cmd.readInt(1));
        builder.append("\r\n");

        builder.append("开始时间："+cmd.readBCD(6));
        builder.append("\r\n");
        builder.append("结束时间："+cmd.readBCD(6));
        builder.append("\r\n");

        builder.append("报警标识1："+cmd.readBCD(4));
        builder.append("\r\n");
        builder.append("报警标识2："+cmd.readBCD(4));
        builder.append("\r\n");

        int type = cmd.readInt(1);
        HashMap<Integer,String> typeList = new HashMap<>();
        typeList.put(0,"音视频");
        typeList.put(1,"音频");
        typeList.put(2,"视频");
        typeList.put(3,"视频或音频");

        builder.append("音视频类型("+type+")："+typeList.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        int stream = cmd.readInt(1);
        HashMap<Integer,String> streamList = new HashMap<>();
        streamList.put(0,"所有码流");
        streamList.put(1,"主码流");
        streamList.put(2,"子码流");

        builder.append("码流类型("+stream+")："+streamList.getOrDefault(stream,"未定义"));
        builder.append("\r\n");

        int storage = cmd.readInt(1);
        HashMap<Integer,String> storageList = new HashMap<>();
        storageList.put(0,"主存储器或灾备存储器");
        storageList.put(1,"主存储器");
        storageList.put(2,"灾备存储器");
        builder.append("存储器类型("+storage+")："+storageList.getOrDefault(storage,"未定义"));
        builder.append("\r\n");

        int condition = cmd.readInt(1);
        builder.append("任务执行条件："+condition);
        builder.append("\r\n");

        builder.append("    WIFI状态："+(((condition&0x01) == 0x01)?"可用":"不可用"));
        builder.append("\r\n");
        builder.append("    LAN状态："+(((condition>>1&0x01) == 0x01)?"可用":"不可用"));
        builder.append("\r\n");
        builder.append("    3G/4G状态："+(((condition>>2&0x01) == 0x01)?"可用":"不可用"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String handle9207(JTT1078_2016Cmd cmd) {
        StringBuilder builder = new StringBuilder();
        builder.append("LCD->Hisi:文件上传控制0x9207（终止历史视频导出）");
        builder.append("\r\n");
        builder.append("应答流水号："+cmd.readWORD());
        builder.append("\r\n");

        int type = cmd.readInt(1);
        HashMap<Integer,String> typeList = new HashMap<>();
        typeList.put(0,"暂停");
        typeList.put(1,"继续");
        typeList.put(2,"取消");

        builder.append("结果("+type+")："+typeList.getOrDefault(type,"未定义"));
        builder.append("\r\n");

        return builder.toString();
    }

    private String checkProtocolStr(JTT1078_2016Cmd cmd, byte[] data) {
        StringBuilder builder = new StringBuilder();

        if (data[0] != 0x7e){
            builder.append("数据包头错误(正常包头：7E)："+HexUtils.toHexStr(new byte[]{data[0]}));
            builder.append("\r\n");
            return builder.toString();
        }

        if (data[data.length - 1] != 0x7e){
            builder.append("数据包尾错误(正常包尾：7E)："+HexUtils.toHex(data[data.length - 1],1));
            builder.append("\r\n");
            return builder.toString();
        }

        builder.append("命令字："+cmd.readOrder());
        builder.append("\r\n");

        int len = cmd.len();
        int checkLen = cmd.leftSize();

        builder.append("长度位："+cmd.len());
        builder.append("\r\n");

        builder.append("长度位校验("+(len == checkLen?"数据正常":"数据异常")+"):"+checkLen);
        builder.append("\r\n");

        builder.append("数据区："+cmd.readBCD(cmd.leftSize()));
        builder.append("\r\n");

        return builder.toString();
    }
}
